//0. 引入数据库模块
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('data.db');

//1. 加载 http 核心模块
var http = require('http')
var server = http.createServer()
server.on('request', function (request, response) {
  // http://127.0.0.1:3000/ /
  // http://127.0.0.1:3000/foo/b /foo/b
  var path = request.url;
  console.log('收到客户端的请求，请求路径是=' + path);
  
  db.get("select * FROM   tb_mock where code = ?",[path], (err, rows) => {
       response.write(rows.value);  //写数据,可以写多次  
	  response.end(); //结束响应
	});
})

server.listen(8000, function () {
  console.log('服务器启动成功了，可以通过 http://127.0.0.1:8000/ 来进行访问')
})


